﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Dycox.Reporting
{
    public class FontStyle : Style
    {
        public static readonly string DefaultFamilyName = SystemFonts.DefaultFont.FontFamily.Name;
        public static readonly float DefaultSize = SystemFonts.DefaultFont.Size;

        public FontStyle(string familyName, float size)
        {
            FamilyName = familyName;
            Size = size;
        }

        public FontStyle()
        {
        }

        public FontStyle(Font font)
        {
            FamilyName = font.FontFamily.Name;
            Size = font.Size;
            Bold = font.Bold;
            Italic = font.Italic;
            Underline = font.Underline;
        }

        public string FamilyName
        {
            get { return GetValueOrDefault<string>("Family", DefaultFamilyName); }
            set
            {
                SetValue("Family", value);
            }
        }

        public float Size
        {
            get { return GetValueOrDefault<float>("Size", DefaultSize); }
            set
            {
                if (value < 1f)
                    throw new ArgumentOutOfRangeException();

                SetValue("Size", value);
            }
        }

        public bool Bold
        {
            get { return GetValueOrDefault<bool>("Bold"); }
            set { SetValue("Bold", value); }
        }

        public bool Italic
        {
            get { return GetValueOrDefault<bool>("Italic"); }
            set { SetValue("Italic", value); }
        }

        public bool Underline
        {
            get { return GetValueOrDefault<bool>("Underline"); }
            set { SetValue("Underline", value); }
        }

        public Font CreateFont()
        {
            System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular;

            if (Bold) style |= System.Drawing.FontStyle.Bold;
            if (Italic) style |= System.Drawing.FontStyle.Italic;
            if (Underline) style |= System.Drawing.FontStyle.Underline;

            return new Font(FamilyName, Size, style);
        }


    }
}
